<template>
  <div
    id="preForms"
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
  >
    <el-card class="box-card">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="事业部维度" name="first">
            <el-row>
                <el-col :xs="24" :sm="24" :lg="24">
                    <div id="reportrange" class="form-control">
                        <div class="item">
                            <label for="cascader">事业部/项目:</label>
                            <el-cascader
                            clearable
                            multiple
                            placeholder="请选择"
                            :options="deptOptions"
                            filterable
                            :show-all-levels="false"
                            :collapse-tags="true"
                            @change="deptSearch"
                            :props="props"
                            style="margin-left: 10px; width:17%"
                            id="cascader"
                            >
                            </el-cascader>
                           
                            <label for="select" style="margin-left:50px">正式项目/潜在项目概率:</label>
                            <el-select
                            v-model="chance"
                            multiple
                            :show-all-levels="false"
                            @change="chanceSearch"
                            :props="props"
                            placeholder="请选择"
                            collapse-tags
                            clearable
                            filterable
                            style="margin-left: 10px; width:17%">
                                <el-option
                                    v-for="item in chanceOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    :disabled="item.disabled"
                                >
                                </el-option>
                            </el-select>
                        </div>
                        
                        <div style="margin-top:15px">
                            <label for="select" style="margin-right: 20px">主技术/产品中心:</label>
                            <el-select
                            v-model="Produnction"
                            multiple
                            @change="tecSearch($event,'主技术中心/主产品中心')"
                            placeholder="请选择"
                            collapse-tags
                            clearable
                            filterable
                            style="width: 150px;margin-top: -70px;">
                                <el-option
                                    v-for="item in ProdunctionOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    :disabled="item.disabled"
                                >
                                </el-option>
                            </el-select>
                            <label for="select" style="margin-right: 20px;margin-left:62px">时间筛选:</label>
                            <el-date-picker
                            v-model="value1"
                            type="monthrange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="changeDateRange">
                            </el-date-picker>
                        </div>
                    </div>
                </el-col>
                <el-button type="primary" plain round style="float: right; margin: 10px 0 10px 0;" @click="down()">导出</el-button>
            </el-row>
            <el-card class="box-card">
                <el-table 
                :data="tableData"
                border 
                max-height="700"
                v-loading="loading" 
                element-loading-text="拼命加载中" 
                element-loading-spinner="el-icon-loading" 
                :header-cell-style="{ background: '#eef1f6',height:'80px' }"
                :cell-style="{padding:'1px'}"
                show-summary 
                :summary-method="getSummaries"
                >
                    <el-table-column prop="label" label="正式项目/潜在项目概率" width="180"  align="center" fixed="left">
                    </el-table-column>
                    <el-table-column  label="事业部" min-width="180" align="center" fixed="left">
                        <template slot-scope="scope">
                            <div v-for="(v,i) in scope.row.value" :key="i">
                                <div v-if="scope.row.value.length == '1'">
                                    {{ v.dept_name }}
                                </div>

                                <div v-if="scope.row.value.length > '1'" class="borders">
                                    {{ v.dept_name }}
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column  label="收入求和" width="150" align="center">
                        <template slot-scope="scope"> 
                            <div v-for="(v,i) in scope.row.value" :key="i">
                                <div v-if="scope.row.value.length == '1'">
                                    {{ v.sum_income | rounding }}
                                </div>
                                <div v-if="scope.row.value.length > '1'" class="borders">
                                    {{ v.sum_income | rounding }}
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="工时求和" width="150" align="center">
                    <template slot-scope="scope">
                        <div v-for="(v,i) in scope.row.value" :key="i">
                            <div v-if="scope.row.value.length == '1'">
                                {{ v.sum_site_power | rounding }}
                            </div>

                            <div v-if="scope.row.value.length > '1'" class="borders">
                                {{ v.sum_site_power | rounding }}
                            </div>
                        </div>
                    </template>
                    </el-table-column>
                    <el-table-column label="人均收入" width="150" align="center">
                    <template slot-scope="scope">
                        <div v-for="(v,i) in scope.row.value" :key="i">
                            <div v-if="scope.row.value.length == '1'">
                                {{ v.per_capita_income | rounding }}
                            </div>

                            <div v-if="scope.row.value.length > '1'" class="borders">
                                {{ v.per_capita_income | rounding }}
                            </div>
                        </div>
                    </template>
                    </el-table-column>
                    <el-table-column :prop="val"  v-for="(val,i) in monthRange"  :label="val+'收入'" width="150" align="center" :key="i" type="incomecell">
                    <template slot-scope="scope">
                        <div v-for="(v,i) in scope.row.value" :key="i" >
                            <div v-if="scope.row.value">
                                <div v-if="scope.row.value.length == '1'">
                                {{ v.forecast_data[val] | rounding }}
                            </div>
                            <div v-if="scope.row.value.length > '1'" class="borders">
                                {{ v.forecast_data[val] | rounding}}
                            </div>
                            </div>
                            
                        </div>
                    </template>
                    </el-table-column>
                    <el-table-column :prop="val" v-for="(val,i) in monthRange"  :label="val+'人月'" width="150" align="center" :key="i+'A'" type="moncell">
                    <template slot-scope="scope">
                        <div v-for="(v,i) in scope.row.value" :key="i+'B'">
                            <div v-if="scope.row.value.length == '1'">
                                {{ v.month_site_power[val] | rounding }}
                            </div>

                            <div v-if="scope.row.value.length > '1'" class="borders">
                                {{ v.month_site_power[val] | rounding }}
                            </div>
                        </div>
                    </template>
                    </el-table-column>
                    <el-table-column :prop="val" v-for="(val,i) in monthRange"  :label="val+'人均收入'" width="180" align="center" :key="i+'C'" type="revcell">
                    <template slot-scope="scope">
                        <div v-for="(v,i) in scope.row.value" :key="i+'D'">
                            <div v-if="scope.row.value.length == '1'">
                                {{ v.month_per_capita_income[val] | rounding }}
                            </div>

                            <div v-if="scope.row.value.length > '1'" class="borders">
                                {{ v.month_per_capita_income[val] | rounding }}
                            </div>
                        </div>
                    </template>
                    </el-table-column>
                </el-table>
                <!-- <el-pagination
                    class="marT"
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="current"
                    :page-size="baseSize"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
                    style="margin-top:10px;margin-left:34%"
                    >
                </el-pagination> -->
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="当月收入异常确认" name="second">
              <el-row>
                <el-col :xs="24" :sm="24" :lg="24">
                    <div id="reportrange" class="form-control">
                        <div class="item">
                            <label for="cascader">事业部/项目:</label>
                            <el-cascader
                            clearable
                            multiple
                            placeholder="请选择"
                            :options="deptOptions"
                            filterable
                            :show-all-levels="false"
                            :collapse-tags="true"
                            @change="deptSearch"
                            :props="props"
                            style="margin-left: 10px; width:17%"
                            id="cascader"
                            >
                            </el-cascader>
                           
                            <label for="select" style="margin-left:50px">正式项目/潜在项目概率:</label>
                            <el-select
                            v-model="chance1"
                            multiple
                            :show-all-levels="false"
                            @change="chanceSearch"
                            :props="props"
                            placeholder="请选择"
                            collapse-tags
                            clearable
                            filterable
                            style="margin-left: 10px; width:17%">
                                <el-option
                                    v-for="item in chanceOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    :disabled="item.disabled"
                                >
                                </el-option>
                            </el-select>
                        </div>
                        
                        <div style="margin-top:15px">
                            <label for="select" style="margin-right: 20px">主技术/产品中心:</label>
                            <el-select
                            v-model="Produnction1"
                            multiple
                            @change="tecSearch"
                            placeholder="请选择"
                            collapse-tags
                            clearable
                            filterable
                            style="width: 150px;margin-top: -70px;">
                                <el-option
                                    v-for="item in ProdunctionOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    :disabled="item.disabled"
                                >
                                </el-option>
                            </el-select>
                            <label for="select" style="margin-right: 20px;margin-left:62px">时间筛选:</label>
                            <el-date-picker
                            v-model="value2"
                            type="month"
                            placeholder="选择月"
                            @change="changeDateRange1">
                            </el-date-picker>
                           
                        </div>
                    </div>
                </el-col>
                <div>
                    <el-button type="primary" plain round style="float: right; margin: 10px 0 10px 0;" @click="down1()">导出</el-button>
                <el-upload
                    v-if="hasUpdate"
                    style="float: right; "
                    class="upload-demo"
                    :action="getActionUrl()"
                    :before-upload="beforeUpload"
                    :on-error="uploadFail"
                    :on-success="uploadSuccess"
                    :on-change="handleChange"
                    :show-file-list="false"
                    :headers="headers">
                    <el-button plain round type="success" style="margin: 10px 10px 10px 0;">导入</el-button>
                </el-upload>
                </div>
                
            </el-row>
            <el-card class="box-card">
                <el-table 
                :data="tableData1"
                border 
                max-height="700" 
                style="width:99.9%" 
                v-loading="loading" 
                element-loading-text="拼命加载中" 
                element-loading-spinner="el-icon-loading" 
                :header-cell-style="{ background: '#eef1f6',height:'80px' }"
                :cell-style="{padding:'15px'}"
                :cell-class-name="addClass"
                >
                    <el-table-column prop="project_name" label="项目" width="180" align="center" fixed="left"></el-table-column>
                    <el-table-column prop="dept_name"  label="事业部" width="180" align="center" fixed="left"> </el-table-column>
                    <el-table-column prop="kh_zh" label="客户" width="150" align="center"></el-table-column>
                    <el-table-column prop="business_type" label="业务类型" width="150" align="center"></el-table-column>
                    <el-table-column prop="pm_zh" label="PM" width="130" align="center"></el-table-column>
                    <el-table-column  prop="forecast_month_actual_income" label="滚动预测当月收入" width="150" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.forecast_month_actual_income | rounding}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="month_actual_income" label="当月实际收入" width="150" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.month_actual_income | rounding}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="month_actual_cost" label="当月实际成本" width="150" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.month_actual_cost | rounding}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="month_profit_margin" label="当月利润率(%)" width="120" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.month_profit_margin | rounding}}
                        </template>
                    </el-table-column>
                     <el-table-column prop="profit_margin" label="立项利润率(%)" width="120" align="center">
                         <template slot-scope="scope">
                            {{ scope.row.profit_margin | rounding}}
                        </template>
                     </el-table-column>
                    <el-table-column prop="income_deviation" label="收入偏差" width="150" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.income_deviation | rounding}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="profit_margin_deviation" label="利润率偏差(%)" width="120" align="center">
                        <template slot-scope="scope">
                            {{ scope.row.profit_margin_deviation | rounding}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="dec" label="偏差说明" width="150" align="center">
                        <template slot-scope="scope">
                            <div v-if="!scope.row.showEdiBtn">
                                <el-input type="textarea" v-model="scope.row.dec" clearable></el-input>
                            </div>
                            <div v-else>
                                {{scope.row.dec}}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="finance_dec" label="财务收入确认说明" width="150" align="center"></el-table-column>
                    <el-table-column prop="time" label="最后更新时间" width="150" align="center"></el-table-column>
                    <el-table-column prop="up_user" width="100" label="更新人"  align="center"></el-table-column>
                    <el-table-column label="操作" width="110"  align="center" fixed="right">
                        <template slot-scope="scope">
                        <el-button type="primary"  plain size="mini" v-show="scope.row.showEdiBtn" :disabled="!scope.row.is_pm"  @click="editFn(scope.$index,scope.row)">编辑</el-button>
                        <el-button type="success" plain size="mini" v-show="!scope.row.showEdiBtn" @click="saveFn(scope.$index,scope.row)" >保存</el-button>
                        <el-button type="warning" plain size="mini" v-show="!scope.row.showEdiBtn" @click="cancelFn(scope.$index,scope.row)" style="margin-top:10px" >取消</el-button>
                        </template>

                    </el-table-column>
                </el-table>
            </el-card>

            <el-pagination
                class="marT"
                background
                @size-change="handleSizeChange1"
                @current-change="handleCurrentChange1"
                :current-page="current1"
                :page-size="baseSize1"
                layout="total, prev, pager, next, jumper"
                :total="total1"
                style="margin-top:10px;margin-left:34%"
                >
            </el-pagination> 
          </el-tab-pane>
        </el-tabs>
      
    </el-card>
    </div>
</template>

<script>
import { getHeaderName } from '@/app.config'
import VTitle from '@/views/sys/internetThings/title';
import http from '@/views/sys/axios';
import { getHeader } from '@/app.config';

export default {
  inject: ['reload'],
  name: 'PredictionsForms',
  components: {
    VTitle,
  },
  data() {
    return {
      hasUpdate:false,
      chanceOptions:[   
          {
              value:'30%',
              label:'30%'
          },
          {
              value:'50%',
              label:'50%'
          },
          {
              value:'80%',
              label:'80%'
          },
          {
              value:'正式项目',
              label:'正式项目'
          },
      ],
      chance:'',
      chance1:'',
      tabName:'first',
      tab:'0',
      tab1:'0',
      paramsData:{},
      paramsData1:{},
      current:1,
      current1:1,
      baseSize:10,
      baseSize1:15,
      total:0,
      total1:0,
      monthRange:[],
      monthRange1:[],
      value1:'',
      value2:'',
      tecArea:'',
      tecArea1:'',
      Produnction:'',
      Produnction1:'',
      ProdunctionOptions:[],
      props: { multiple: true },
      deptOptions:[],
      dept:'',
      dept1:'',
      activeName: 'first',
      loading: false,
      cusLoading: false,
      tableData: [],
      tableData1: [],
      parData : {},
      headers: getHeader(),
    };
  },
  filters: {
    rounding (value) {
      if(value || value === 0) {
        return Number(value).toFixed(2)
      }
    }
  },
  mounted(){
   this.getTableData()
   this.getDeptOptions()
   this.getTableData1()
   this.getProdunctionOptions()
  },
  watch:{
  },
  methods: {
      addClass({row,column,rowIndex,columnIndex}){
        if(column.label == "收入偏差" && row.income_deviation < 0){
            return 'cell-zore'
        }
        if(column.label == "利润率偏差(%)" && row.profit_margin_deviation < 0){
            return 'cell-zore'
        }
     },
      cancelFn(index,row){
          row.showEdiBtn = true
          this.$set(this.tableData,index,row)
      },
      getActionUrl(){
          	return (`${process.env.VUE_APP_KANBAN_HOST}/api/data_summary/car/roll/month_project_update_data`)
      },
      beforeUpload(file) {
        let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
        const isExcel = extension == "xlsx" || extension == "xls" || extension == "csv"
        this.loading = true
        if (!isExcel) {
            this.$message.warning("文件格式不对（只支持.xlsx|.xls|.csv文件）");
        }
     },
     uploadFail() {
      var self = this
			self.loading = false
			self.$message.error('上传失败')
		},
    uploadSuccess(res) {
      var self = this
      self.loading = false
      if (res.code === 200) {
        this.$message({
          message: "导入成功",
          type: 'success',
        });
        this.getTableData1()
      }if(res.code === 400){
        this.$message({
            message: '导入内容不正确',
            type: 'error'
          });
      }

    },
    handleChange(file, fileList) {
    this.fileList = fileList;
    },
      saveFn(index,row){
          console.log(row)
          row.showEdiBtn = true
          this.parData["project_id"] = row.project_id
          this.parData["dec"] = row.dec
          this.parData['month'] = row.month
          http.post(`/api/data_summary/car/roll/month_project_update_dec`,this.parData)
          .then((res => {
              if(res.code === 200){
                  this.$message({
                    message: res.msg,
                    type: 'success'
                })
                this.getTableData1()
              }
          }))
      },
      editFn(index,row){
          row.showEdiBtn = false
          this.$set(this.tableData,index,row)
      },
      getProdunctionOptions(){
        let data = {}
        data['name'] = '主技术中心/主产品中心'
        http.post(`/api/data_summary/car/roll/condition`,data)
        .then((res => {
            if(res.code === 200){
            this.ProdunctionOptions = res.msg
            }
        }))
    },
      getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        //循环处理所有列数据
        columns.forEach((column, index) => {
            if (index === 0) {
            sums[index] = '总计';
            return;
            }
            //将每列的所有数据数字化处理成一个数组
            if(index === 2){ // 判断为收入求和时
                if(data.length === 4){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 3){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 2){
                    let newarr=[...data[0].value,...data[1].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 1){
                    let newarr=[...data[0].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
            }
            if(index === 3){ // 判断为工时求和时
                if(data.length === 4){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_site_power)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 3){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_site_power)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 2){
                    let newarr=[...data[0].value,...data[1].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_site_power)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 1){
                    let newarr=[...data[0].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.sum_site_power)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
            }
            if(index === 4){ // 判断为人均收入时
                if(data.length === 4){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.per_capita_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 3){
                    let newarr=[...data[0].value,...data[1].value,...data[2].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.per_capita_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 2){
                    let newarr=[...data[0].value,...data[1].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.per_capita_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
                if(data.length === 1){
                    let newarr=[...data[0].value]
                    let temp = []
                    newarr.map(key => {
                        temp.push(key.per_capita_income)
                    })
                    var s = 0
                    for(let i=temp.length-1;i>=0;i--){
                        s += temp[i]
                    }
                    return sums[index] = s.toFixed(2)
                }
            }
            let values = []
            data.map(item => {
                if(column.type == 'incomecell') {  //判断收入
                    if(data.length === 4){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.forecast_data)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 3){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.forecast_data)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 2){
                        let newarr=[...data[0].value,...data[1].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.forecast_data)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 1){
                        let newarr=[...data[0].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.forecast_data)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                } 
                if(column.type == 'moncell'){ //判断人月
                    if(data.length === 4){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_site_power)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 3){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_site_power)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 2){
                        let newarr=[...data[0].value,...data[1].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_site_power)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 1){
                        let newarr=[...data[0].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_site_power)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                }
                if(column.type == 'revcell'){ //判断人月
                    if(data.length === 4){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value,...data[3].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_per_capita_income)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 3){
                        let newarr=[...data[0].value,...data[1].value,...data[2].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_per_capita_income)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 2){
                        let newarr=[...data[0].value,...data[1].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_per_capita_income)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                    if(data.length === 1){
                        let newarr=[...data[0].value]
                        let temp = []
                        newarr.map(key => {
                            temp.push(key.month_per_capita_income)
                        })
                         values = temp.map(v => {
                            return v[column.property]
                        })
                    }
                }
                else {
                    return NaN
                }
                });
                //当前列的所有数据全是数字类型时
                if (!values.every(value => isNaN(value))) {
                //将当前列数据数组中的所有值，从左到右依次累加处理
                sums[index] = values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                    return (parseFloat(prev) + parseFloat(curr)).toFixed(2);
                    } else {
                    return parseFloat(prev).toFixed(2)
                    }
                }, 0);
                } else {
                sums[index] = '';
                }
            });
        return sums;
    },
      chanceSearch(e){
        if(this.tabName==="first"){
            this.paramsData["status"] = e
            this.current = 1
            this.getTableData()
        }else if(this.tabName==="second"){
            this.paramsData1["status"] = e
            this.current1 = 1
            this.getTableData1()
        }
      },
    down1(){
        this.loading = true
        this.$axios({
            url: process.env.VUE_APP_KANBAN_HOST + '/api/data_summary/car/roll/download_month_project_data',
            method: "get",
            headers: getHeaderName(),
            responseType: 'blob',
        }).then(res => {
        if(res.status === 200) {
            this.loading = false
            const blob = new Blob([res.data]);
            const fileName = '滚动预测-当月收入异常确认.xlsx';
            // for IE
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(blob, fileName)
        } else {
            // for Non-IE (chrome, firefox etc.)
            const elink = document.createElement('a');
            elink.download = fileName;
            elink.style.display = 'none';
            elink.href = URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            URL.revokeObjectURL(elink.href);
            document.body.removeChild(elink);
            this.loading = false
            this.$message({
            type:"success",
            message:"导出成功!"
            })
        }} else {
            this.loading = false
            this.$message.error('下载出错了!'); 
            }
            }).catch(err => {
                this.$message.error('下载出错了!'); 
                this.loading = false
            })
    },
    down(){
        this.loading = true
        this.$axios({
            url: process.env.VUE_APP_KANBAN_HOST + '/api/data_summary/car/roll/probability_table_data_to_excel',
            method: "get",
            headers: getHeaderName(),
            responseType: 'blob',
        }).then(res => {
        if(res.status === 200) {
            this.loading = false
            const blob = new Blob([res.data]);
            const fileName = '滚动预测-事业部维度.xlsx';
            // for IE
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(blob, fileName)
        } else {
            // for Non-IE (chrome, firefox etc.)
            const elink = document.createElement('a');
            elink.download = fileName;
            elink.style.display = 'none';
            elink.href = URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            URL.revokeObjectURL(elink.href);
            document.body.removeChild(elink);
            this.loading = false
            this.$message({
            type:"success",
            message:"导出成功!"
            })
        }} else {
            this.loading = false
            this.$message.error('下载出错了!'); 
            }
            }).catch(err => {
                this.$message.error('下载出错了!'); 
                this.loading = false
            })
    },
    changeDateRange1(e){
         var date = new Date(e)
         var year = date.getFullYear(); 
         var month = date.getMonth() + 1; 
         let parDataM = `${year}年${month}月`
         this.paramsData1['month'] = parDataM
         this.current1 = 1
         this.getTableData1()
           
    },
    changeDateRange(e){
            let arr = []
            let arr1 = []
            let startData = e[0]
            let endData = e[1]
            var YY1 = startData.getFullYear() 
            var MM1 = (startData.getMonth() + 1 < 10 ? '0' + (startData.getMonth() + 1) : startData.getMonth() + 1) ;
            arr.push(YY1 , MM1)
            arr = arr.map(v=>{
                if (v[0] == "0") {
                return (v = v.slice(1));
                } else {
                return v;
                }
            })
            let startTime = arr.join("-")
            var YY2 = endData.getFullYear() 
            var MM2 = (endData.getMonth() + 1 < 10 ? '0' + (endData.getMonth() + 1) : endData.getMonth() + 1) ;
            arr1.push(YY2 , MM2)
            arr1 = arr1.map(v=>{
                if (v[0] == "0") {
                return (v = v.slice(1));
                } else {
                return v;
                }
            })

            let endTime = arr1.join("-")
            this.paramsData['start_date'] = startTime
            this.paramsData['end_date'] = endTime
            this.current = 1
            this.getTableData()
    },
    tecSearch1(){},
    tecSearch(val){
        if(this.tabName==="first"){
            this.paramsData["core"] = val
            this.current = 1
            this.getTableData()
        }else if(this.tabName==="second"){
            this.paramsData1["core"] = val
            this.current1 = 1
            this.getTableData1()
        }
    },
    getTecOptions(){ },
    getDeptOptions(){
        http.get(`/api/data_summary/car/roll/list_tree`)
        .then((res) => {
            if(res.code === 200) {
                this.deptOptions = res.project_list
            }
        })
    },
    deptSearch(val){
        let valArr = []
        val.map(key => {
            valArr.push(key[2])
        })
        if(this.tabName==="first"){
            this.paramsData["project_ids"] = valArr
            this.current = 1
            this.getTableData()
        }else if(this.tabName==="second"){
            this.paramsData1["projects"] = valArr
            this.current1 = 1
            this.getTableData1()
        }
    },
    handleCurrentChange1(val) {
        this.current1 = val;
        this.getTableData1()
    },
    handleSizeChange1(val){
    },
    handleCurrentChange(val) {
    // this.current = val;
    // this.getTableData()
    },
    handleSizeChange(val){
    },
    getTableData(){
       this.loading = true
       this.paramsData["page"] = this.current
       http.post(`/api/data_summary/car/roll/probability_table_data`,this.paramsData)
       .then((res => {
          if(res.code === 200){
            this.loading = false
            this.tableData = res.data
            this.monthRange = res.month_range
          }else{
            this.loading = false
            this.$message.error('请求出错')
          }
        }))
    },
    getTableData1(){
       this.loading1 = true
       this.paramsData1["page"] = this.current1
       this.$axios({
          url: process.env.VUE_APP_KANBAN_HOST + '/api/data_summary/car/roll/month_project_data',
          method: "post",
          headers: getHeaderName(),
          data:this.paramsData1
        }).then((res => {
          if(res.data.code === 200){
            this.loading1 = false
            this.tableData1 = res.data.result
            this.hasUpdate = res.data.has_update
            this.tableData1.map(item =>{
                item.showEdiBtn = true
            })
            this.total1 = res.data.count
            
          }else{
            this.loading1 = false
            this.$message.error('请求出错')
          }
        }))
    },
    handleClick(tab, event) {
      this.tabName = tab.name
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.el-table--medium th, .el-table--medium td {
    padding: 0px 0 !important; 
}
/deep/.el-table__body-wrapper{
    z-index: 2
}
/deep/ .el-table td.cell-zore { 
  background-color:#eb070763 !important;
  color: #82848a;
}
/deep/td:first-child .cell {
    padding-left: 10px;
    padding: 13px;
}
#preForms{
//   .tabWidth{
//       width:500px
//   }
  label {
    color:  #2b2f32;
    font-weight: bold;
  };
  .form-control {
    background-color: #ffffff;
    background-image: none;
    border: 1px solid #e5e6e7;
    border-radius: 1px;
    color: inherit;
    display: block;
    padding: 6px 12px;
    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    width: 100%;
    font-size: 0.9rem;
    box-shadow: none;
    margin-bottom: 10px
  };
  .borders{
    border-bottom: 1px solid #c5c4c1;
    height: 40px;
    width: 120%;
    margin-left: -14px;
    margin-top:10px;
    // margin-bottom:10px;
  };
  .borders1{
    border-bottom: 1px solid #c5c4c1;
    height: 32px;
    width: 183px;
    margin-left: -14px;
    margin-top:10px;
    // margin-bottom:10px;
  };
  .borders2{
    // border-bottom: 1px solid #c5c4c1;
    height: 25px;
    width: 120%;
    margin-left: -14px;
    margin-top:10px;
    // margin-bottom:10px;
  };
}
</style>